/**************************************************************************
 *
 * Copyright (c) 2002 - 2011 by Computer Architecture Department,
 * Universitat Politecnica de Catalunya.
 * All rights reserved.
 *
 * The contents of this file may not be disclosed to third parties,
 * copied or duplicated in any form, in whole or in part, without the
 * prior permission of the authors, Computer Architecture Department
 * and Universitat Politecnica de Catalunya.
 *
 */

/**************************************************
Implementation of a D3DPlayer specialized in
*.PIXRun files with D3D9 calls.

Author: José Manuel Solís
**************************************************/

#ifndef __D3D9PIXRUNPLAYER
#define __D3D9PIXRUNPLAYER

#include "PIXTypes.h"

class D3D9PixRunPlayer: public D3DPlayer, public D3DTrace  {
public:
    /*************************
    D3DPlayer implementation
    **************************/
    void open(std::string filename);
    void close();
    bool playBatch();
    bool playFrame();
    unsigned long getCallOffset();
    void *getDirect3DDevice();
    
    bool isEndOfFrame();
    
    /*************************
    D3DTrace implementation
    **************************/
    bool next();
    bool getFrameEnded();
    u32bit getCurrentEventID();
    bool isPreloadCall();

    void setWindow(HWND window);

    D3D9PixRunPlayer();

private:
    unsigned long callOffset;
    bool frameEnded;

    u32bit currentFrame;
    u32bit currentBatch;
    
    D3D9PixRunReader reader;
    D3D9Status status;
    
    bool endOfFrame;
    
    /******************
    Executes command fetched by reader
    ******************/
    void execute();

    enum D3D9CID {
        // Autogenerated code that enumerate all possible call names
        #include "D3D9PixRunEnum.gen"
    };

    //  Specific code functions (debug)
    inline void Direct3DCreate9_SPECIFIC_PRE();
    inline void IDirect3D9_CreateDevice_SPECIFIC_POST(HRESULT result, IDirect3DDevice9* returnedDeviceInterface);
    inline void IDirect3D9_CreateDevice_SPECIFIC_PRE(UINT &adapter, D3DDEVTYPE &deviceType,
                                                     HWND &hFocusWindow, 
                                                     DWORD &behaviorFlags,
                                                     D3DPRESENT_PARAMETERS *&pp);
    //inline void IDirect3D9_CreateTexture_SPECIFIC_POST(IDirect3DTexture9* texture);
    inline void IDirect3DCubeTexture9_LockRect_SPECIFIC_POST(IDirect3DCubeTexture9 *sip_This,
                                                             D3DCUBEMAP_FACES faceType, UINT level,
                                                             D3DLOCKED_RECT *lockedRect, RECT *pRect);
    inline void IDirect3DCubeTexture9_UnlockRect_SPECIFIC_PRE(IDirect3DCubeTexture9 *sip_This,
                                                              D3DCUBEMAP_FACES faceType, UINT level);



    // Declarations for all stub functions
    #include "D3D9PixRunDeclarations.gen"

};

#endif
